#include "transContentFuncCallContructPath.hpp"

//////////////////////////////////////////////////////////////////////
/// response packet format:
///		name | mainCode | subCode | localPort |target | result | pathType | pathlen | path |
///		len  |    1     |    1    |   4       |  8    |   1    |    1     |    1    |  len |
///  offset  |    0     |    1    |   2       |  6    |   14   |   15     |    16   |  17  |
///
/// the path is char index for auto path, is nodeAddr for fixed
///
/// parameters:
///		buffer: the response buffer
///		index: the buffer index in memory pool
///
/// return:
///		RESPONSE_RESULT_DELETE_RECORD: remove the port record
int transContentConstructPath::response(char* buffer, int index){
	int mainCode = buffer[1];
	NodeAddr _target = *((NodeAddr*)(buffer+1));
	debug_enter();
	getFixedPathResult = buffer[14];
	if(getFixedPathResult == 1){
		pathType = buffer[15];
		pathLen = buffer[16];
		memset(path, 0x00, 44);
		memcpy(path, buffer+17, pathLen);
	}
	logd_info("begin to release the buffer space");
	TransContentMemory::getInstance()->releaseBuffer(index);
	logd_info("extract info from packet sucessfully");
	// let wait thread to goon
	pthread_mutex_lock(&waitMutex);
	pthread_cond_signal(&waitCond);
	pthread_mutex_unlock(&waitMutex);
	sleep(SYNC_METHOD_RETURN_TIME);
	return RESPONSE_RESULT_DELETE_RECORD;
}
